/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tjsinfo.tjsoa.message.vo;

import com.jacob.activeX.*;
import com.jacob.com.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 *
 * @author nerv
 */
public class BigAnt_api {

    static ActiveXComponent smsg = new ActiveXComponent("AntCom.AntMsg");
    static ActiveXComponent sses = new ActiveXComponent("AntCom.AntSyncSession");
    static ActiveXComponent sinfo = new ActiveXComponent("AntCom.AntLoginInfo");
    private String mode="";
    private String sander="";
    private String accept="";
    private String sanderPass="";
    private String serverIp="";
    private String serverPort="";

    public String getAccept() {
        return accept;
    }

    public void setAccept(String accept) {
        this.accept = accept;
    }

    public String getSander() {
        return sander;
    }

    public void setSander(String sander) {
        this.sander = sander;
    }

    public String getSanderPass() {
        return sanderPass;
    }

    public void setSanderPass(String sanderPass) {
        this.sanderPass = sanderPass;
    }
        public String getServerIp() {
        return serverIp;
    }

    public void setServerIp(String serverIp) {
        this.serverIp = serverIp;
    }

    public String getServerPort() {
        return serverPort;
    }

    public void setServerPort(String serverPort) {
        this.serverPort = serverPort;
    }

    /*
     * (题目，正文)
     * 发送信息
     */
    public String SendMassage(String baTitle, String baContent) {

        Dispatch msg = (Dispatch) smsg.getObject();

        if (mode.isEmpty()) {
            return ("BigAnt_api SetMode is NULL");}
        Dispatch.put(msg, "ContentType", mode);
      

        Dispatch.put(msg, "Subject", baTitle);
        Dispatch.put(msg, "Content", baContent);

        //设置接受者
        if (accept.isEmpty()) {
            return ("BigAnt_api accept is NULL");}
        Dispatch.call(msg, "AddReceiver", accept, "");

        Dispatch info = (Dispatch) sinfo.getObject();
        //Dispatch.put(msg,"AddAttach","c:\111.txt"); 

        //设置服务器IP
        if (serverIp.isEmpty()) {
            return ("BigAnt_api serverIP is NULL");}
        Dispatch.put(info, "Server", serverIp);
        //设置服务器端口
        if (serverPort.isEmpty()) {
            return ("BigAnt_api serverPort is NULL");}
        Dispatch.put(info, "ServerPort", serverPort);
        //设置发送者
        if (sander.isEmpty()) {
            return ("BigAnt_api sander is NULL");}
        Dispatch.put(info, "LoginName", sander);
        //设置发送者密码
        if (sanderPass.isEmpty()) {
            return ("BigAnt_api sanderPass is NULL");}
        Dispatch.put(info, "PassWord", sanderPass);

        Dispatch ses = (Dispatch) sses.getObject();
        Dispatch.call(ses, "Login", info);
        Dispatch.call(ses, "SendMsg", msg, 0);
        
        
        return "OK";//"SUCCESS";
        
    }
    
    
    
    /*
     * 必填项3-1
     * 设置接收方式为Url
     */

    public void SetModeUrl() {
        this.mode = "Text/Url";
    }
    /*
     * 必填项3-1
     * 设置接收方式为Html
     */

    public void SetModeHtml() {
        this.mode = "Text/Html";
    }
    /*
     * 必填项3-1
     * 设置接收方式为Text
     */

    public void SetModeText() {
        this.mode = "Text/Text";
    }

    /*
     * 必填项3-1
     * 设置接收方式为Url
     */
    public void SetAccept(String accept) {
        this.mode = "Text/Html";
    }


    /*
     * 从配置文件messageResource.properties中获取IP
     * @return
     */
    private String getFilePath()
    { 
            Properties props = new Properties();
            ClassLoader cl = this.getClass().getClassLoader();
            InputStream is = cl.getResourceAsStream("com/tjsinfo/tjsoa/login/articles/properties/messageResource.properties"); 
            try {
                    props.load(is);
            } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
            } 
            String strFilePath = props.getProperty("serverip");
            return strFilePath;
    }

}
